<?php

namespace app\common\service;


use app\common\model\SellerModel;

class SellerService
{
    public function _info($id)
    {
        $db   = new SellerModel();
        $info = $db->where('id', $id)->find();
        return json(['code' => 0, 'msg' => '获取成功', 'data' => $info]);
    }

    public function _list($page,$limit)
    {
        $db    = new SellerModel();
        $list  = $db->page($page)->limit($limit)->select();
        $count = $db->count('id');
        return json(['code' => 0, 'msg' => '获取成功', 'data' => $list, 'count' => $count]);
    }

    public function login($phone, $password)
    {
        $db    = new SellerModel();
        $info = $db->where('phone', $phone)->find();
        if (!$info) {
            return ['code' => 0, 'msg' => '账户不存在'];
        }
        if ($info['password'] != md5($password)) {
            return ['code' => 0, 'msg' => '账户或密码错误'];
        }
        session('sellerid', $info['id']);
        session('sellername', $info['username']);
        return ['code' => 1, 'msg' => '登录成功'];
    }
}
